<template>
  <section class="app-inner">
    <!--    <el-card class="header-card">-->
    <!--      <el-form :inline="true" :model="queryParams">-->
    <!--        <el-form-item label="日志名称">-->
    <!--          <el-input-->
    <!--              clearable-->
    <!--              placeholder="请输入日志名称"-->
    <!--              v-model="queryParams.logTitle"-->
    <!--          ></el-input>-->
    <!--        </el-form-item>-->
    <!--        <el-form-item>-->
    <!--          <el-button type="primary" @click="onSubmit" style="margin-left:30px;">查询</el-button>-->
    <!--          <el-button type="primary" @click="handleSynchro">刷新</el-button>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--    </el-card>-->
    <el-card class="table-card">
      <!--      <el-table border :data="tableData" style="width: 100%">-->
      <!--        <el-table-column prop="sceneNo" label="场景编号"></el-table-column>-->
      <!--        <el-table-column prop="sceneName" label="场景名称"></el-table-column>-->
      <!--        <el-table-column prop="dispatchUrl" label="跳转地址"></el-table-column>-->
      <!--      </el-table>-->
      <el-tree :data="treeData" :props="defaultProps" node-key="pkId" default-expand-all></el-tree>
      <!--      <el-pagination-->
      <!--          class="page-class"-->
      <!--          layout="total, prev, pager, next"-->
      <!--          @current-change="pageHandleChange"-->
      <!--          :current-page="pageNum"-->
      <!--          :total="totalPageNum"-->
      <!--      ></el-pagination>-->
    </el-card>
  </section>
</template>

<script>
import { getUserScene } from './js/scene'

export default {
  data () {
    return {
      pageNum: 1,
      pageSize: 10,
      totalPageNum: 0,
      queryParams: {
        logTitle: ''
      },
      tableData: [],
      treeData: [],
      defaultProps: {
        label: 'name'
        // children: 'permissionInfoList',
        // label: (data, node) => {
        //   if (node.level === 1) {
        //     return data.sceneName
        //   } else if (node.level === 2) {
        //     return data.name
        //   }
        // }
      }
    }
  },
  components: {},
  mounted () {
    this.getUserScene()
  },
  methods: {
    async getUserScene () {
      let { code, data, msg } = await getUserScene()
      if (code === 0) {
        this.treeData = this.recursionTree(data.sceneTreeResps)
      } else {
        this.$message.warning(msg)
      }
    },
    // 递归处理tree结构数据
    recursionTree (result) {
      const treeData = []
      if (result && result.length !== 0) {
        result.forEach(item => {
          if (item.isEnable === 0) return
          let obj = {
            pkId: item.pkId,
            name: item.parentId === '0' ? item.sceneName : item.name
          }
          if (item.children && item.children.length > 0) {
            obj.children = this.recursionTree(item.children)
          }
          treeData.push(obj)
        })
      }
      return treeData
    }
  }
}
</script>

<style lang="scss" scoped></style>
